package l.l.w.leetcode.JumpGameII;

import java.util.LinkedList;
import java.util.List;

/**
 * Created by llw on 2017/11/9.
 */
public class JumpGameII {

    public int jump(int[] nums) {
        if(nums == null ) return 0;
        int length = 0;
        int step = 0;
        for(int i = 0 ; i < nums.length;){
            step++;
            if(nums[i] + i >= nums.length-1) break;
            int max = 0;
            int index = 0;
            for(int j = 1; j <= nums[i]; ++j){
                length = i + j;
                if(length + nums[i+j] > max) {
                    max = length+nums[i+j];
                    index = i+j;
                }
            }
            i = index;
        }
        return step;
    }

    public static void main(String[] args) {
        int[] a = {2,3,1,1,4};
        int result = new JumpGameII().jump(a);
        System.out.println(result);

    }
}
